<?php
/**
 * Created by PhpStorm.
 * User: Dark
 * Date: 2015/8/16
 * Time: 14:29
 */

namespace Admin\Controller;


use Think\Controller;

class LoginController extends Controller
{
    /*
     * 检测是否存在该员工
     */
    public function isEmployee() {
        if(!empty($_POST)) {
            $employee = D('employee');
            $result = $employee->isEmployee($_POST['phoneNumber']);
            if(!empty($result)) {
                $data['status'] = 1;
                $data['info'] = '欢迎回来！';
            } else{
                $data['status'] = -1;
                $data['info'] = '账号不存在！请检查后输入！';
            }
        } else {
            $data['status'] = 0;
            $data['info'] = '传入数据为空！';
        }
        echo json_encode($data);
    }

    /*
     * 员工登录
     */
    public function login() {
        if(!empty($_POST)) {
            $employee = D('employee');
            $result = $employee->login($_POST);
            if(!empty($result)) {
                $data['status'] = 1;
                $data['info'] = "欢迎回来！";
                $data['url'] = U("/Admin/Index/index");
                session("EmployeeInfo",$result[0]);
            } else {
                $data['status'] = -1;
                $data['info'] = '密码与账号不相符！';
            }
        } else {
            $data['status'] = 0;
            $data['info'] = '账号和密码都必须填写！';
        }
        echo json_encode($data);
    }
}